<?php

/**
 * workorder actions.
 *
 * @package    buzzwork
 * @subpackage workorder
 * @author     Kasa
 * @version    SVN: $Id: actions.class.php 1415 2006-06-11 08:33:51Z fabien $
 */

class workorderActions extends sfActions
{
  public function executeIndex ()
  {
    return $this->forward('workorder', 'list');
  }

  public function executeList ()
  {
    $this->pager = WorkorderPeer::GetWorkorderPager($this->getRequestParameter('page', 1));
  }

  public function executeRecent ()
  {
    $this->pager = WorkorderPeer::GetRecentPager($this->getRequestParameter('page', 1));
  }

  public function executeMy ()
  {
    $this->pager = WorkorderPeer::GetMyPager($this->getRequestParameter('page', 1), $this->getUser()->getSubscriberId());
  }

  public function executeShow ()
  {
    $this->workorder = WorkorderPeer::retrieveByPk($this->getRequestParameter('id'));
    $this->forward404Unless($this->workorder);
  }

  public function executeCreate ()
  {
    $this->workorder = new Workorder();

    $this->setTemplate('edit');
  }

  public function executeEdit ()
  {
    $this->workorder = WorkorderPeer::retrieveByPk($this->getRequestParameter('id'));
    $this->forward404Unless($this->workorder);
  }

  public function executeUpdate ()
  {
    if (!$this->getRequestParameter('id', 0))
    {
      $workorder = new Workorder();
    }
    else
    {
      $workorder = WorkorderPeer::retrieveByPk($this->getRequestParameter('id'));
      $this->forward404Unless($workorder);
    }

    $workorder->setId($this->getRequestParameter('id'));
    $workorder->setCompanyId($this->getRequestParameter('company_id'));
    $workorder->setPmId($this->getRequestParameter('pm_id'));
    $workorder->setTechId($this->getRequestParameter('tech_id'));
    if ($this->getRequestParameter('status'))
    	$workorder->setStatus($this->getRequestParameter('status'));
    else 
    	$workorder->setStatus('1');
    	
    $workorder->setName($this->getRequestParameter('name'));
    $workorder->setNumber($this->getRequestParameter('number'));
    $workorder->setDescription($this->getRequestParameter('description'));

    $workorder->save();

    return $this->redirect('workorder/show?id='.$workorder->getId());
  }

  public function executeDelete ()
  {
    $workorder = WorkorderPeer::retrieveByPk($this->getRequestParameter('id'));

    $this->forward404Unless($workorder);

    $workorder->delete();

    return $this->redirect('workorder/list');
  }
}
